<?php
namespace app\common\middleware;
use app\common\repositories\system\SystemVisitRecordRepository;
use app\Request;

/**
 * Created by PHPStorm
 * User: xiest
 * Date: 2021/12/13
 * Email: <939369942@qq.com>
 */

class ApiVisitRecordMiddleware{

    public function handle(Request $request,\Closure $next)
    {
        try {
            $data['uid'] = $request->uid();
        }catch (\Exception $e){
            $data['uid'] = 0;
        }
        try {
            $data['ip'] = ip2long($request->ip());
            $data['create_time'] = time();
            $data['path'] = $request->rule()->getRule();
            /*$data['request_data'] = $request->post() + $request->get();*/
            app()->make(SystemVisitRecordRepository::class)->create($data);
        }catch (\Exception $e){}

        return $next($request);
    }
}